/*
 * Copyright (c) 2020-2099 the original author or authors. All rights reserve.
 */
package org.tianyun.cloud.openfeign.interceptors;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.tianyun.cloud.context.RequestContext.RequestContextHolder;
import org.tianyun.cloud.context.ServletContext.ContextOperator;
import org.tianyun.cloud.context.ServletContext.ServletContextHolder;

/**
 * 上下文信息拦截处理
 *
 * @auther ebert_chan
 */
public class ServletContextInterceptor implements RequestInterceptor {

    /*
     * @see feign.RequestInterceptor#apply(feign.RequestTemplate)
     */
    @Override
    public void apply(RequestTemplate requestTemplate) {
        ContextOperator operator = (key, value) -> {
            requestTemplate.header(key, value);
        };
        RequestContextHolder.dispatch(operator);
        ServletContextHolder.dispatch(operator);
    }

}
